// let baseUrl = 'http://api.zhuishushenqi.com'; //接口域名
// let baseUrl = '/chapter2'; //接口域名
import store from "@/store"
// let baseUrl = '/api'; //接口域名
let reqCount = 0,
	resCount = 0; //记录请求次数和响应次数
const request = (options) => {
	let baseUrl=store.state.baseUrl
	reqCount++;
	uni.showLoading();
	return new Promise((resolve, reject) => {
		uni.request({
			method: options.method,
			url: baseUrl + options.url,
			dataType:options.dataType,
			data: options.data,
			header: options.header //如需其他配置可在此添加或先转换options.url，然后 ...options
		}).then((response) => {
			resCount++
			if (reqCount === resCount) uni.hideLoading(); //防止连续请求多个接口时loading闪现
			let [error, res] = response;
			resolve(response);
		}).catch(error => {
			resCount++
			if (reqCount === resCount) uni.hideLoading();
			let [err, res] = error;
			reject(err)
		})
	});
}
export default request
